package com.kun.controller;

import com.kun.entity.JdContent;
import com.kun.service.SearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;

/**
 * @author kun.li
 */
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchController {

    private final SearchService searchService;

    /**
     * 搜索
     */
    @GetMapping("/{page}/{size}/{keyword}")
    public List<JdContent> searchDataList(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size,
            @PathVariable("keyword") String keyword) {
        return searchService.searchList(page, size, keyword);
    }

    /**
     * 自动补全
     */
    @GetMapping("/autoCompletion/{keyword}")
    public Collection<String> suggestionList(@PathVariable("keyword") String keyword) {

        return searchService.suggestionList(keyword);
    }

}
